total number of images

Hi to all.
I made my own theme, and now i want to show the total number of the images i have in different albums. I'd like to have it on the index.php page of my template.
I noticed that if i use the getTotalImagesIn function without parameters it didn't work.
I'm pretty ignorant in php :(
I tried this but it dont work
<php? $number = getTotalImagesIn(); if ($number > 1) $number .= " photos"; else $number .=" photo"; echo$number; ?>

Any help???

Thanks in advance

Comments

  • acrylian Administrator, Developer
    Try getNumImages() instead of getTotalImagesIn().
  • alredy tried. It seems wherever I insert getNumImages() or getTotalImagesIn() functions in the index.php page it simply block the page.
    It seems to work on my album.php page instead.
    I wonder why.. Missing parameters?
    If u want to take a look my ZP gallery is in filmposter.netsons.org/zenphoto/index.php
  • acrylian Administrator, Developer
    You need to place getNumImage() within the albums loop that starts with `<?php while (next_album()): ?>` since it returns only the images of one album. getTotalimages instead returns the number of images in an album and all of it's subalbums.
    Please take a look at our functions guide, too.

    If you mean the total number of all images in all albums? There is no function for that if I recall correctly. Use something like this:
    `<?php $photosArray = query_single_row("SELECT count(*) FROM ".prefix('images')); $photosNumber = array_shift($photosArray); echo $photosNumber ?>`(taken from stopdesign theme).

    Probably worth considering a standard function for that.
  • From class-gallery.php:

    `

    224 /**

    225 * Returns the number of images from a database SELECT count(*)

    226 * Ideally one should call garbageCollect() before to make sure the database is current.

    227 * @return int

    228 */

    229 function getNumImages() {

    230 $result = query_single_row("SELECT count(*) FROM ".prefix('images'));

    231 return array_shift($result);

    232 }

    `
  • acrylian Administrator, Developer
    Oh, right, there it is... To make it complete, gregluk, use it this way `<?php echo $_zp_gallery->getNumImages(); ?>`
  • Thanks a lot. Now i'll give a try to your tips. Indeed i'm looking for a function that returns total numbers of images in the whole gallery, as shown in the gallery stats on the admin page. There it works, i hoped there was something similare for the templates.
    If u look at my pages, u'll find that i did 26 albums (A, B, C, etc.) to make a gallery browsable by the starting letter of an image's name. So a function that returns total numbers of images in all allbums would be nice for me.

    Thanks a lot and please excuse my english, I'm from Italy ;)
  • selim Member
    also you can use <?php echo getTotalImagesIn($_zp_current_album);?> for total images in sub albums.
  • hi,

    I'm looking for a function like getNumImages() but I would like to exclude images from unpublished albums, is it possible ?

    in my template, I use this code

    [code]
    <?php $photosArray = query_single_row("SELECT count(*) FROM ".prefix('images')); $photosNumber = array_shift($photosArray); echo $photosNumber ?>
    [/code]

    I have a lot of unpublished albums (images and docs used in a CMS, files are shared between the CMS and ZP). Around 60% of images are in unpublished albums (± 2500 images)

    thanks

    ps: sorry for my english, I'm french
  • acrylian Administrator, Developer
    I haven't tried yet, but if you are logged in there are no "unpublished" albums/images. The admin sees them all.

    Actually `getNumImages()` gets only the image count of the current selected album.
    You could try instead using the gallery class method `$_zp_gallery->getNumImages()` that gets the count of all images of your gallery.
  • thanks acrylian

    I've tried but the count is the same with `$_zp_gallery->getNumImages()`
    I tried to see with orther browsers, clean all cookies, history, etc... but I have the total of images (published and unpublished albums)
    I don't know if the problem is coming from my computer or not, you can see my gallery (still under construction) here :
    http://www.bilin-village.org/photos/
  • gregluk: WOW Love the site even if I can't read the words :) What PHP function did you use to add "subtitles" to the thumbnails (album.php page)?
  • acrylian Administrator, Developer
    What is the number of images you have? I see a count of 4816 .
  • 1813 images in 18 published albums ... and 4816 in all abums
  • acrylian Administrator, Developer
    Ok, we found out that this function does indeed not care about published or not. We will have a fix in one of the next nigthlies.
  • ok thanks, I'll check it... and thanks for zenphoto, really nice "tool"... I could manage to include albums and recent images in other pages from my website (powered by Plume CMS)

    - a happy new user
  • Tonight's nightly build will allow you to pass a parameter `$gallery->getNumImages(true)` to return the count of only published images. Likewise `$gallery->getNumAlbums(true, true)` for published albums.
  • Please "pardonnez moi" OT..
    Hi macalter, thanks for your good words. That was a site I did a lot time ago. I programmed to translate it into english but i never did it...
    To make subtitles to image thumbnails I symply made a div beneath the div with the thumbnail with <?php printImageTitle();?> in it. A little adjustament by CSS and it worked very fine
  • hi,

    I've updated my ZP install with the latest nighly version (5/06) and tried `$gallery->getNumImages(true)` but the count is still the total of all images (I'm not logged on the gallery)... must I uncheck "visible" for images in unpublished albums ?

    Gallery (http://www.bilin-village.org/photos/) :
    - albums : 18 - 1806 images
    - total images : 4752

    Admin Tool (Gallery Stats)
    - 4752 images (2884 unpublished)
    - 39 albums (18 unpublished)
  • acrylian Administrator, Developer
    It's working for me with the latest svn 1679, please try tonight's nightly again.
  • Also go to your admin overview page. You should see statistics on unpublished albums and images with the new changes.

    Admin is using the new calls to get this information, so if it shows the data, the function is working.

    Have you initialized your `$gallery` variable? Perhaps you should be using `$_zp_gallery`
  • thanks !

    I've tried `$_zp_gallery->getNumImages(true)`, it's almost perfect (some images should not be counted)

    it will be long and difficult for me to explain the problem in english, I've made a screenshot with the "description" of the problem, I think it's linked with subalbums

    http://img527.imageshack.us/img527/1010/image2hz6.png
  • Try running a refresh database to clean up any orphaned albums or images. Also note that if you are looking at the database table, there may be one extra album and two extra images in it that are not counted.
  • thanks

    I've tried before and did it again when I read your message but nothing changes... it's not so important, I think images counted are in subalbums even if they are not published

    I'll deal with it because I choose to share the same folder for ZP albums and a CMS, and these subalbums contain images for the CSS of the CMS

    for the moment, my problem is to understand how does ZP works when I add new images on existing albums via FTP...

    I've searched and read subjects on the forum and don't understand yet (english is not my first language, it doesn't help)

    I've checked this :

    - safe_mode is OFF
    - mod_rewrite is ON
    - cache folder + every folder in cache folder have 777 permission
    - each folder in "album folder" has 755 permission
    - each image in album folder has 644 permission
    - thumbnails created in cache folders have 666 permission

    when I send images via FTP :
    - count on the gallery is OK (new images are in)
    - if I look the gallery, new images are not there, it's normal because if I look in the database new images are not there (no new entry)

    I'm trying to understand when entries are created in the database :
    1) wait half an hour to see if new images will be created in the database > no
    2) refresh the database > no
    3) I try "pre-cache images" (without checking "clear") on the admin, after 40 minutes, Safari stopped loading the page (5317 errors - timeout mention in acitivty window) > but it works, new images are in the DB

    yesterday, I've tried something else : edit the album on the admin, it creates also entries in the DB for new images but loading the "album page" is too slow for galeries over 400 images (more than 5 minutes for 400 images)

    using "pre-cache" or "edit the album" on the admin tool are too slowly to update "big gallery"... for me, it's better to use phpMyAdmin to update informations (title, etc) for saving time...

    what should I do ?

    how does it works when images are uploaded by FTP ?

    sorry for the "off-topic" (and maybe redundant subject) but I'm trying to understand
  • New entries are created in the database when the album/image is "viewed". You can force that to happen by the `pre-cache` functions. The getNumImages() function counts database records, either published or all.
  • ok

    I find a way to use "pre-cache" very quickly, in `cache-images.php`, I comment this :

    `echo 'image | image' . "n";`

    my solution is :
    - pre-cache, everytime I send new pics
    - use phpmyadmin to update data in "big galleries", otherwise the admin is cool for "small galleries"

    sorry if I bother you... I'll be a nice quiet girl now...
  • acrylian Administrator, Developer
    'll deal with it because I choose to share the same folder for ZP albums and a CMS, and these subalbums contain images for the CSS of the CMS
    There actually should be only images/albums that are to be used for zenphoto in the albums folder. Confusion is preprepared if you put css images in there. I would recommend to keep images for "styling" separate from the "content" ones.
  • I chose zenphoto because I could share this folder between galleries and the CMS, essential points of my checklist were:
    - share my "media folder" (didn't want to duplicate images)
    - using same image in a ZP gallery or, for example, in an article or a slideshow included in an article
    - publish latest images on the homepage (CMS)
    - publish albums on a special page (CMS)

    this folder contains docs, images, etc for 3 websites (same website in 3 languages) and also galleries... images I use for ZP galleries are in folders untitled "alb_" and contain only images (folders don't start by the prefix "alb_" are unpublished precisely to avoid confusion)
  • acrylian Administrator, Developer
    Ok, I understand, I maybe was a too little quick with my answer. That indeed works. Which CMS do you use?

    EDIT: I see you use Plume CMS.
  • don't worry... also, maybe my answers sound "quick" (or "hard"), I don't know "polite things" to make nice sentences in english
  • acrylian Administrator, Developer
    No problem with your english...:-) (BTW, english is not my native language, too)
Sign In or Register to comment.